package com.example.dessertstoressm.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dessertstoressm.Mapper.ProductMapper;
import com.example.dessertstoressm.Service.ProductService;
import com.example.dessertstoressm.domain.Product;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    ProductMapper productMapper;

    @Override
    public List<Product> getProductListByCategory(String categoryId){
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.eq("category",categoryId);
        return this.productMapper.selectList(wrapper);
    }

    @Override
    public Product getProduct(String productId){
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.eq("productid",productId);
        return this.productMapper.selectOne(wrapper);
    }

    @Override
    public List<Product> searchProductList(String keywords){
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.like("name",keywords);
        return this.productMapper.selectList(wrapper);
    }
}
